<?php
ob_start();
//include('common/db.php');
include('common/xta.php');
include('common/xpath.php');

$xta = new xta();

function getList() {
	$xp = new xp();
	$xta = new xta();
	
	$all_companies = $xp->getData('company-list', 'http://money.rediff.com/gainers/bse/monthly');
	$limit = 10;
	$data = array();
	foreach($all_companies as  $each_company) {
		
		if(isset($limit) && ($limit == $counter)) break; else $counter++;
		
		$company_info = $xp->getData('company-info', $each_company['url']);
		
		$data[] = $company_info;		
	}
	
	$xta->data = $data;
	$xta->filename = 'stocks';
	$xta->saveAs('stocks', 'bsc_code');	
}

function getDayMoves() {
	$xp = new xp();
	$xta = new xta();
	
	$xta->load('stocks');
	$all_stocks = $xta->data['stocks'];
		
	foreach($all_stocks as $each_stock) {
		
		if(isset($limit) && ($limit == $counter)) break; else $counter++;

		$company_data = $xp->getData('stock-move-day', $each_stock['bsc_code']);
		$xta->data = $company_data;
		$xta->filename = $each_stock['bsc_code'];
		$xta->save('days', 'day');
	}
}

function getMonthMoves() {
	$xp = new xp();
	$xta = new xta();
	$xta->load('stocks');
	$all_stocks = $xta->data['stocks'];
	
	foreach($all_stocks as $each_stock) {
		
		if(isset($limit) && ($limit == $counter)) break; else $counter++;
 		
		$company_data = $xp->getData('stock-move-month', $each_stock['bsc_code']);
		$xta->data = $company_data;
		$xta->filename = $each_stock['bsc_code']."_monthly";
		$xta->save('months', 'month');
	}
}

getList();
//getDayMoves();
//getMonthMoves();
?>
